package cn.ctbu.edu.labtest.service.impl;

import cn.ctbu.edu.labtest.dao.StudentRepository;
import cn.ctbu.edu.labtest.domain.student;
import cn.ctbu.edu.labtest.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StudentImpService implements StudentService {

    @Autowired
    StudentRepository studentRepository;
    /*读取所有数据*/
    public List<student> findAll(){

        return studentRepository.findAll();
    }

    public Page<student> findAll(Pageable pageable){
        return studentRepository.findAll(pageable);
    }
    /*插入*/
    public student insert(student student){

        return studentRepository.save(student);
    }
    /*跟新*/
    public student update(student student){

        return studentRepository.save(student);
    }

    /*删除*/
    public void delete(student student){

        studentRepository.delete(student);
    }
    public void delete(Long id){
        student student=new student();
        student.setId(id);
        studentRepository.delete(student);
    }

    public student getById(Long id){
        student student=studentRepository.findById(id).orElse(null);
        return student;
    }

    public Page<student> findAll(Example<student> student, Pageable pageable){
        return studentRepository.findAll(student,pageable);
    }
}

